#include <cstdio>
#include <memory.h>
#include <queue>
#include <iostream>
using namespace std;

struct node {
	int x, w;
	node(int v, int wi) {x = v; w = wi;}
};

int dis[100005];
bool vis[100005];
queue<int> q;
vector<node> G[100005];

void spfa() {
	memset(dis, 0, sizeof(dis));
	memset(vis, 0, sizeof(vis));
	dis[1] = 0x7fffffff;
	vis[1] = 1;
	q.push(1);
	while (q.size()) {
		int x = q.front();
		q.pop();
		//cout << "break point 2 at x = " << x << endl;
		vis[x] = 0;
		for (unsigned i = 0; i < G[x].size(); ++i) {
			int y = G[x][i].x, z = G[x][i].w;
			if (dis[y] < min(dis[x], z)) {
				dis[y] = min(dis[x], z);
				//cout << x << "-->" << y << "  " << dis[y] << endl;
				if (!vis[y]) {
					q.push(y);
					vis[y] = 1;
				}
			}
		}
	}
}

int main() {
	int n;
	cin >> n;
	int u, v, w;
	while (1) {
		cin >> u >> v >> w;
		if (u == v && v == w && w == 0) break; 
		G[u].push_back(node(v, w));
	}

	//cout << "break point 1." << endl;

	spfa();

	for (int i = 2; i <= n; ++i) {
		cout << dis[i] << endl;
	}
	return 0;
}